//
//  FollowTopicOfSubscriberModel.m
//
//  Created by mac  on 2018/11/26
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "FollowTopicOfSubscriberModel.h"


NSString *const kFollowTopicOfSubscriberModelTopicalName = @"TopicalName";
NSString *const kFollowTopicOfSubscriberModelAbstract = @"Abstract";
NSString *const kFollowTopicOfSubscriberModelFollowNum = @"FollowNum";
NSString *const kFollowTopicOfSubscriberModelCoverPic = @"CoverPic";
NSString *const kFollowTopicOfSubscriberModelArticleNum = @"ArticleNum";
NSString *const kFollowTopicOfSubscriberModelTopicalType = @"TopicalType";
NSString *const kFollowTopicOfSubscriberModelID = @"ID";


@interface FollowTopicOfSubscriberModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation FollowTopicOfSubscriberModel

@synthesize topicalName = _topicalName;
@synthesize abstract = _abstract;
@synthesize followNum = _followNum;
@synthesize coverPic = _coverPic;
@synthesize articleNum = _articleNum;
@synthesize topicalType = _topicalType;
@synthesize iDProperty = _iDProperty;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.topicalName = [self objectOrNilForKey:kFollowTopicOfSubscriberModelTopicalName fromDictionary:dict];
            self.abstract = [self objectOrNilForKey:kFollowTopicOfSubscriberModelAbstract fromDictionary:dict];
            self.followNum = [[self objectOrNilForKey:kFollowTopicOfSubscriberModelFollowNum fromDictionary:dict] doubleValue];
            self.coverPic = [self objectOrNilForKey:kFollowTopicOfSubscriberModelCoverPic fromDictionary:dict];
            self.articleNum = [[self objectOrNilForKey:kFollowTopicOfSubscriberModelArticleNum fromDictionary:dict] doubleValue];
            self.topicalType = [[self objectOrNilForKey:kFollowTopicOfSubscriberModelTopicalType fromDictionary:dict] doubleValue];
            self.iDProperty = [[self objectOrNilForKey:kFollowTopicOfSubscriberModelID fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.topicalName forKey:kFollowTopicOfSubscriberModelTopicalName];
    [mutableDict setValue:self.abstract forKey:kFollowTopicOfSubscriberModelAbstract];
    [mutableDict setValue:[NSNumber numberWithDouble:self.followNum] forKey:kFollowTopicOfSubscriberModelFollowNum];
    [mutableDict setValue:self.coverPic forKey:kFollowTopicOfSubscriberModelCoverPic];
    [mutableDict setValue:[NSNumber numberWithDouble:self.articleNum] forKey:kFollowTopicOfSubscriberModelArticleNum];
    [mutableDict setValue:[NSNumber numberWithDouble:self.topicalType] forKey:kFollowTopicOfSubscriberModelTopicalType];
    [mutableDict setValue:[NSNumber numberWithDouble:self.iDProperty] forKey:kFollowTopicOfSubscriberModelID];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.topicalName = [aDecoder decodeObjectForKey:kFollowTopicOfSubscriberModelTopicalName];
    self.abstract = [aDecoder decodeObjectForKey:kFollowTopicOfSubscriberModelAbstract];
    self.followNum = [aDecoder decodeDoubleForKey:kFollowTopicOfSubscriberModelFollowNum];
    self.coverPic = [aDecoder decodeObjectForKey:kFollowTopicOfSubscriberModelCoverPic];
    self.articleNum = [aDecoder decodeDoubleForKey:kFollowTopicOfSubscriberModelArticleNum];
    self.topicalType = [aDecoder decodeDoubleForKey:kFollowTopicOfSubscriberModelTopicalType];
    self.iDProperty = [aDecoder decodeDoubleForKey:kFollowTopicOfSubscriberModelID];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_topicalName forKey:kFollowTopicOfSubscriberModelTopicalName];
    [aCoder encodeObject:_abstract forKey:kFollowTopicOfSubscriberModelAbstract];
    [aCoder encodeDouble:_followNum forKey:kFollowTopicOfSubscriberModelFollowNum];
    [aCoder encodeObject:_coverPic forKey:kFollowTopicOfSubscriberModelCoverPic];
    [aCoder encodeDouble:_articleNum forKey:kFollowTopicOfSubscriberModelArticleNum];
    [aCoder encodeDouble:_topicalType forKey:kFollowTopicOfSubscriberModelTopicalType];
    [aCoder encodeDouble:_iDProperty forKey:kFollowTopicOfSubscriberModelID];
}

- (id)copyWithZone:(NSZone *)zone
{
    FollowTopicOfSubscriberModel *copy = [[FollowTopicOfSubscriberModel alloc] init];
    
    if (copy) {

        copy.topicalName = [self.topicalName copyWithZone:zone];
        copy.abstract = [self.abstract copyWithZone:zone];
        copy.followNum = self.followNum;
        copy.coverPic = [self.coverPic copyWithZone:zone];
        copy.articleNum = self.articleNum;
        copy.topicalType = self.topicalType;
        copy.iDProperty = self.iDProperty;
    }
    
    return copy;
}


@end
